﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Diagnostics;

namespace WPP_Console
{
    /// <summary>
    /// Message listener, singlton pattern.
    /// Inherit from DependencyObject to implement DataBinding.
    /// </summary>
    public class MessageListener : DependencyObject
    {
        private static MessageListener mInstance;

        private MessageListener ( )
        {
        }

        public static MessageListener Instance
        {
            get
            {
                if ( mInstance == null )
                    mInstance = new MessageListener ( );
                return mInstance;
            }
        }

        public void ReceiveMessage ( string message )
        {
            Message = message;
            Debug.WriteLine ( Message );
            DispatcherHelper.DoEvents ( );
        }
       
        public string Message
        {
            get { return ( string ) GetValue ( MessageProperty ); }
            set { SetValue ( MessageProperty, value ); }
        }

        public static readonly DependencyProperty MessageProperty =
            DependencyProperty.Register ( "Message", typeof ( string ), typeof ( MessageListener ), new UIPropertyMetadata ( null ) );

    }
}
